import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/refresh")
public class RefreshServlet extends HttpServlet {

//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        // 设置 header, 实现每隔 1s 自动刷新页面的效果. 页面上要显示当前时间戳
//        resp.setHeader("refresh", "1");
//        resp.getWriter().write("" + System.currentTimeMillis());
//    }





    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 使用 SimpleDateFormat 类, 让页面上能够显示格式化的事前. 例如 2022-01-19 12:00:00
        resp.setHeader("refresh", "3");
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        resp.getWriter().write(ft.format(new Date()));
    }
}
